package org.jdpf.gui.rcp.neteditor.core.blocks;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.jdpf.core.kernel.plugins.IPluginsFrameworkConstants;
import org.jdpf.gui.rcp.neteditor.core.elements.GraphicNet;
import org.osgi.framework.Bundle;

public class GGenerator extends AbstractGraphicBlock {

	private int widthOval = 20;
	private int widthRectangle = 40;
	private int widthTriangle = 20;
	
	public GGenerator(Bundle bundle, GraphicNet gnet) {
		super(bundle, gnet);
		category = IPluginsFrameworkConstants.GENERATOR;
		height = 30;
		width = widthOval + widthRectangle + widthTriangle;
		int connectorLength = 40;
		
		addOutputPosition(new Point(width+connectorLength, 15));
		setTransitionName("Generator transition");
	}

	public void draw(GC gc) {
		super.draw(gc);
		
		Color black = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
		gc.setBackground(black);
		
		gc.fillArc(position.x, position.y, widthOval*2, height, 90, 180);
		
		gc.fillRectangle(position.x + widthOval, position.y, widthRectangle, height);
		
		//Triangle
		gc.fillPolygon(new int[]{
				position.x + widthOval + widthRectangle, position.y,
				position.x + widthOval + widthRectangle, position.y + height,
				position.x + width+1, position.y + (height/2)
		});
		
		
		gc.setBackground(statusColor);
		
		gc.fillRectangle(position.x + widthOval, position.y+1, 
				widthRectangle, height-2);
		
		gc.fillArc(position.x+1, position.y+1, (widthOval*2)-1, height-2, 90, 180);
		
		//Triangle
		gc.fillPolygon(new int[]{
				position.x + widthOval + widthRectangle, position.y + 1,
				position.x + widthOval + widthRectangle, position.y + height - 1,
				position.x + width - 1, position.y + (height/2)
		});
		
		drawOutputConnectors(gc);
	}
}